﻿using System;
using StoneAge.Models.Enums;
using StoneAge.Models.Extension;

namespace StoneAge.Models.Entity
{
    partial class Role
    {
        private const Int32 BASE_STATUS = 20;
        private const Int32 BASE_PROPERTY = 10;
        public const Int32 EVERY_LEVEL_STATUS = 3;

        private Coordinate m_Coordinate = null;
        public virtual Coordinate Coordinate
        {
            get { return m_Coordinate; }
            set { m_Coordinate = value; }
        }

        private Level m_Level = null;
        public virtual Level Level
        {
            get { return m_Level; }
            set { m_Level = value; }
        }

        protected override void Validate()
        {
            if (string.IsNullOrEmpty(Name))
                AddBrokenRule(RoleBrokenRules.NAME_REQUIRED);

            if ((BASE_STATUS + (LevelId - 1) * EVERY_LEVEL_STATUS) != (Vit + Str + Agi + Def + Point))
                AddBrokenRule(RoleBrokenRules.TOTAL_STATUS_INCORRECT);

            if (Land + Water + Fire + Wind <= BASE_PROPERTY)
                AddBrokenRule(RoleBrokenRules.TOTAL_PROPERTY_INCORRECT);

            if (CharacterId < Convert.ToInt32(Character.DouDingGe) || Convert.ToInt32(Character.BiJiMei) > CharacterId)
                AddBrokenRule(RoleBrokenRules.CHARACTER_INCORRECT);

            if (ColorId < Convert.ToInt32(Color.Green) || Convert.ToInt32(Color.Gold) < ColorId)
                AddBrokenRule(RoleBrokenRules.COLOR_INCORRECT);

            if (ExpressionUpId < Convert.ToInt32(ExpressionUp.First) || Convert.ToInt32(ExpressionUp.Fifth) < ExpressionUpId)
                AddBrokenRule(RoleBrokenRules.EXPRESSION_UP_INCORRECT);

            if (ExpressionDownId < Convert.ToInt32(ExpressionDown.First) || Convert.ToInt32(ExpressionDown.Fifth) < ExpressionDownId)
                AddBrokenRule(RoleBrokenRules.EXPRESSION_DOWN_INCORRECT);

            if (DirectionId < Convert.ToInt32(Direction.South) || Convert.ToInt32(Direction.SouthEast) < DirectionId)
                AddBrokenRule(RoleBrokenRules.DIRECTION_INCORRECT);
        }
    }
}
